﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Web;
using System.Web.UI;
using System.Web.UI.WebControls;
using Negocio.Cabelo;

namespace qbaproject.Cabelo.Cor.Consultar
{
    public partial class consultarCorCabelo : System.Web.UI.Page
    {
        private int paginaAtual = 0;

        protected void Page_Load(object sender, EventArgs e)
        {

        }

        protected void lnk_Click(object sender, EventArgs e)
        {
            Response.Redirect("~/Cabelo/Cor/Incluir/incluirCorCabelo.aspx");
        }

        protected void lkbPesquisar_Click(object sender, EventArgs e)
        {
            carregarGrid();
        }

        protected void grdResCorCabelo_PageIndexChanging(object sender, GridViewPageEventArgs e)
        {
            paginaAtual = e.NewPageIndex;
            carregarGrid();
        }

        protected void grdResCorCabelo_RowCommand(object sender, GridViewCommandEventArgs e)
        {
            switch (e.CommandName)
            {
                case "editar":
                    var idCorCabelo = e.CommandArgument.ToString();
                    Response.Redirect("~/Cabelo/Cor/Editar/editarCorCabelo.aspx?id=" + idCorCabelo);
                    break;
                case "remover":
                    var idCorCabeloRemover = e.CommandArgument.ToString();
                    hdfIdCorCabeloRemover.Value = idCorCabeloRemover;
                    ModalPopupRemover.Show();
                    break;
            }
        }

        protected void lkbSim_Click(object sender, EventArgs e)
        {
            var idCorCabelo = Convert.ToInt32(hdfIdCorCabeloRemover.Value);
            var obNPeleCebelo = new NCorCabelo();
            obNPeleCebelo.Remover(idCorCabelo);
            carregarGrid();
        }

        protected void lkbNao_Click(object sender, EventArgs e)
        {
            ModalPopupRemover.Hide();
        }

        private void carregarGrid()
        {
            var obNCorCabelo = new NCorCabelo();
            var obListTipoCabelo = obNCorCabelo.pegarCoresCabelo(txtNmCorCabelo.Text);

            if (obListTipoCabelo.Tables[0].Rows.Count != 0)
            {
                divMsnPesquisaSucesso.Visible = true;
                lblNumEncontrados.Text = "Foram encontrados " + obListTipoCabelo.Tables[0].Rows.Count.ToString() + " registros.";
                divMsnPesquisaAtencao.Visible = false;
            }
            else
            {
                divMsnPesquisaSucesso.Visible = false;
                divMsnPesquisaAtencao.Visible = true;
            }

            grdResCorCabelo.PageSize = 15;
            grdResCorCabelo.AllowPaging = true;
            grdResCorCabelo.PageIndex = paginaAtual;
            grdResCorCabelo.DataSource = obListTipoCabelo;
            grdResCorCabelo.DataBind();
        }

    }
}